// Calculator.java
import java.util.Scanner;

public class Calculator {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double num1, num2, result;
        char operator;

        System.out.println("简单控制台计算器");
        System.out.print("输入第一个数字: ");
        num1 = scanner.nextDouble();

        System.out.print("输入运算符 (+, -, *, /): ");
        operator = scanner.next().charAt(0);

        System.out.print("输入第二个数字: ");
        num2 = scanner.nextDouble();

        switch (operator) {
            case '+':
                result = num1 + num2;
                break;
            case '-':
                result = num1 - num2;
                break;
            case '*':
                result = num1 * num2;
                break;
            case '/':
                if (num2 != 0) {
                    result = num1 / num2;
                } else {
                    System.out.println("错误：除数不能为零!");
                    scanner.close();
                    return;
                }
                break;
            default:
                System.out.println("错误：无效的运算符!");
                scanner.close();
                return;
        }
        System.out.println(num1 + " " + operator + " " + num2 + " = " + result);
        scanner.close();
    }
}